﻿<html>
<head>
    <title>Starlight Sample Player</title>

    <style type="text/css">
    html, body {
	    height: 100%;
	    overflow: auto;
    }
    body {
	    padding: 0;
	    margin: 0;
    }
    #silverlightControlHost {
	    height: 100%;
    }
    </style>
    
    <script type="text/javascript">
        var slCtl;
        var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
        
        function onSilverlightError(sender, args) {
        
            var appSource = "";
            if (sender != null && sender != 0) {
                appSource = sender.getHost().Source;
            } 
            var errorType = args.ErrorType;
            var iErrorCode = args.ErrorCode;
            
            var errMsg = "Unhandled Error in Silverlight 2 Application " +  appSource + "\n" ;

            errMsg += "Code: "+ iErrorCode + "    \n";
            errMsg += "Category: " + errorType + "       \n";
            errMsg += "Message: " + args.ErrorMessage + "     \n";

            if (errorType == "ParserError")
            {
                errMsg += "File: " + args.xamlFile + "     \n";
                errMsg += "Line: " + args.lineNumber + "     \n";
                errMsg += "Position: " + args.charPosition + "     \n";
            }
            else if (errorType == "RuntimeError")
            {           
                if (args.lineNumber != 0)
                {
                    errMsg += "Line: " + args.lineNumber + "     \n";
                    errMsg += "Position: " +  args.charPosition + "     \n";
                }
                errMsg += "MethodName: " + args.methodName + "     \n";
            }
            alert(errMsg);
            throw new Error(errMsg);
        }

        function pluginLoaded(sender, args) {      // HTML version 
            slCtl = sender.getHost();
            var fileProxy;

            //For Google Chrome, we have to proxy all Silverlight<->Native communication
            //through javascript due to a bug in the process isolation in Chrome.
            if (is_chrome) {
                var real_proxy = document.getElementById('FileProxyNS');
                fileProxy = {
                    FetchNSC : function(url) {
                        return real_proxy.FetchNSC(url);
                    },
                    
                    StartStreaming : function(addr, port, target) {
                        var proxyTarget = {
                            AddPacketBase64 : function(data) {
                                target.AddPacketBase64(data);
                            }
                        };
                        
                        real_proxy.StartStreaming(addr, port, proxyTarget);
                    },
                    
                    StopStreaming : function() {
                        real_proxy.StopStreaming();
                    },
                    
                    Test : function(msg) {
                        real_proxy.Test(msg);
                    }
                };
            } else if (document.FileProxyNS) { // Firefox
                fileProxy = document.FileProxyNS;

            } else { // IE/Safari
                fileProxy = document.FileProxy;
            }

            //Uncomment below to test that the native control loaded.
            //fileProxy.Test('hi');
            
            slCtl.Content.Bridge.PlaylistLoaded = function() {
                slCtl.Content.Bridge.StartStreaming(fileProxy);
            };

            
        }


        function removeEntry(button) {
            var ref = button;
            while (ref) {
                if (ref.className == "playlistRow") {
                    break;
                }
                ref = ref.parentNode;
            }

            if (ref) {
                ref.parentNode.remveChild(ref);
            }
        }

        function addRow() {
            var ref = document.getElementById("playlistEntries");
            var child = ref.firstChild;
            while (child) {
                if (child.className == "playlistRow") {
                    break;
                }
                child = child.nextSibling;
            }

            if (child) {
                var n = child.cloneNode(true);
                ref.appendChild(n);
            }
        }

        function setPlaylist() {
            var entries = [];
            var ref = document.getElementById("playlistEntries");
            var child = ref.firstChild;
            while (child) {
                if (child.className == "playlistRow") {
                    var subChild = child.firstChild;
                    while (subChild) {
                        if (subChild.className == "urlField") {
                            entries.push(subChild.value);
                        }
                        try {
                            subChild.disabled = true;
                        } catch (e) {
                        }
                        subChild = subChild.nextSibling;
                    }
                }
                child = child.nextSibling;
            }
            document.getElementById("addRowBtn").disabled = true;
            document.getElementById("playBtn").disabled = true;
            var str = "asx:<ASX>";
            for (var i = 0; i < entries.length; i++) {
                str += "<ENTRY><REF href=\"" + entries[i] + "\"/></ENTRY>";
            }
            str += "</ASX>";
            slCtl.Content.Bridge.LoadPlaylistAsync(str);
        }
    </script>
</head>

<body>
    <!-- A place to put log messages.  Hide this element to hide log messages. -->
    <div id="starlight_multicast_proxy_log">
    </div>
    <div id="scriptEventLog">
    
    </div>
    
    <object 
        id="FileProxy" 
        name="FileProxy" 
        classid="clsid:5CCEF05B-17B2-48F0-A577-CC019FE455D7"
        type="application/x-vnd-starlight-proxy">
    </object>
    <embed id="FileProxyNS" type="application/x-vnd-starlight-proxy"></embed>
    
    <!-- Runtime errors from Silverlight will be displayed here.
	This will contain debugging information and should be removed or hidden when debugging is completed -->
	<div id='errorLocation' style="font-size: small;color: Gray;"></div>

    <div>
        <div id="playlistEntries">
            <div class="playlistRow">
                URL: <input type="text" class="urlField" /> <input type="button" value="x" onclick="removeEntry(this); return false;" />
            </div>
            
            
        </div>
        <div>
            <input type="button" id="addRowBtn" onclick="addRow(); return false;" value="Add Entry" />
            <input type="button" id="playBtn" onclick="setPlaylist(); return false;" value="Play" />
        </div>
    </div>
    <div id="silverlightControlHost">
		<object data="data:application/x-silverlight," type="application/x-silverlight-2" width="100%" height="100%">
			<param name="source" value="bin/release/StarlightSamplePlayer.xap"/>
			<param name="onerror" value="onSilverlightError" />
			<param name="onLoad" value="pluginLoaded" />
			<param name="background" value="gray" />
			<param name="minRuntimeVersion" value="2.0.31005.0" />
			<param name="autoUpgrade" value="true" />
			<a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;">
     			<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>
			</a>
		</object>
		<iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>
    </div>
    <div id="starlightDebugLog" style="overflow: auto; height: 25em;">
    </div>
    
</body>
</html>
